//////////////////////////////////////////////////////////////////////////
//																		//
//	Author:			Michael Mozdzierz									//
//	Date: 			01/16/2015											//
//	Description:	Represents a 2D texture on the graphics device		//
//					handles shader resource, and texture data			//
//																		//
//////////////////////////////////////////////////////////////////////////
#pragma once

#include <D3D11.h>
#include "IGrahpicsResource.h"

#define D3D11_CPU_ACCESS_READWRITE (D3D11_CPU_ACCESS_FLAG)(D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE)

struct PiplineIndex;
class Texture2D : public IGraphicsResource
{
	ID3D11Texture2D* texture = nullptr;

	ID3D11ShaderResourceView* srv = nullptr;

public:
	Texture2D(unsigned int width, unsigned int height, DXGI_FORMAT format, ID3D11Device*const device = nullptr, D3D11_BIND_FLAG bindFlags = D3D11_BIND_SHADER_RESOURCE, D3D11_CPU_ACCESS_FLAG cpu_access = (D3D11_CPU_ACCESS_FLAG)0, D3D11_USAGE usage = D3D11_USAGE_DEFAULT,
		void* existingData = nullptr, unsigned int structSize = 0);
	Texture2D(ID3D11Texture2D* texture);
	~Texture2D(void);

	// get the shader resource view for this texture
	virtual ID3D11ShaderResourceView* getSrv(void) const override;

	// get the D3D11 texture object for this texture
	ID3D11Texture2D* getTexture(void) { return texture; }

	// get the pixel data for the texture
	//		struct size - the size of the pixel type to retrieve from the texture
	virtual void getData(void* data, unsigned int structSize) override;

	// set the pixel data for this texture
	//		struct size - the size of the pixel type to retrieve from the texture
	virtual void setData(void* data, unsigned int structSize) override;
	// gets the width of the resource
	unsigned int getWidth(void) const
	{
		D3D11_TEXTURE2D_DESC desc;
		texture->GetDesc(&desc);
		return desc.Width;
	}


	// gets the d3d11 object that represents the resource
	virtual ID3D11Resource* getResource(void) const override { return (ID3D11Resource*)texture; }

	// gets the height of the resource
	unsigned int getHeight(void) const
	{
		D3D11_TEXTURE2D_DESC desc;
		texture->GetDesc(&desc);
		return desc.Height;
	}
	// gets the d3d11 descriptor for this object and copies it onto 'desc'
	virtual void getDesc(void* desc) override { texture->GetDesc((D3D11_TEXTURE2D_DESC*)desc); }
};